﻿using INTEX.DataBase;
using INTEX.DataBase.Tools;
using ReflectionStudio.Core;
using ReflectionStudio.Core.Events;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.IO;
using System.Linq;
using System.Windows;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{
    public partial class ITXEXRPT
    {
        VHRSTAMM HR;
        public void JLTONAV95(DataSet db)
        {
            VHRSTAMM HR = new VHRSTAMM();
            string msg = "";
            string sdkey = "";
            string src = "";
            try
            {
                DataTable tbMain = tbExport.Clone();
                tbExport.Clear();
                for (int i = 0; i < 400; i++)
                {
                    tbMain.Rows.Add();
                }

                #region======初始化=========
                double jtotal = 0;
                double jstotal = 0;
                double wtotal = 0;
                int page = 0;
                int linep = 42;
                //织机类型		

                tbMain.Rows[page * linep + 0][2] = "张家港市金陵纺织有限公司 盘头整经生产计划单";
                tbMain.Rows[page * linep + 2][1] = "交期:";
                tbMain.Rows[page * linep + 2][4] = "织机类型:";
                tbMain.Rows[page * linep + 2][6] = "计划轴数:";
                tbMain.Rows[page * linep + 2][8] = "布号:";
                //tbMain.Rows[page * linep + 3][1] = "布号:";
                tbMain.Rows[page * linep + 3][1] = "规格:";
                tbMain.Rows[page * linep + 3][6] = "领纱单号:";
                tbMain.Rows[page * linep + 3][8] = "翻单号:";

                tbMain.Rows[page * linep + 29][2] = "订货米数";
                tbMain.Rows[page * linep + 29][3] = "库存成品数";
                tbMain.Rows[page * linep + 29][4] = "盘头整经米数";
                tbMain.Rows[page * linep + 29][5] = "浆纱长度";
                tbMain.Rows[page * linep + 29][6] = "坯布米数";
                tbMain.Rows[page * linep + 29][7] = "成品米数";
                tbMain.Rows[page * linep + 29][8] = "交货范围";
                tbMain.Rows[page * linep + 29][9] = "备注";

                tbMain.Rows[page * linep + 30][1] = "数量";
                tbMain.Rows[page * linep + 31][1] = "织缩";
                tbMain.Rows[page * linep + 31][3] = "整理缩率";
                tbMain.Rows[page * linep + 31][5] = "投料";
                tbMain.Rows[page * linep + 31][7] = "浆纱伸长率";


                tbMain.Rows[page * linep + 34][1] = "编号:JLZ/QR.ZF01";
                tbMain.Rows[page * linep + 34][4] = "制表：";
                tbMain.Rows[page * linep + 34][6] = "审核：";


                tbMain.Rows[page * linep + 11][1] = "色泽";
                tbMain.Rows[page * linep + 11][2] = "色名";
                tbMain.Rows[page * linep + 11][10] = "合计";
                tbMain.Rows[page * linep + 12][2] = "色号";
                tbMain.Rows[page * linep + 13][1] = "数量";
                tbMain.Rows[page * linep + 13][2] = "纱支";

                tbMain.Rows[page * linep + 14][2] = "产地批号";


                //tbMain.Rows[11][3] = "安徽省巢湖市临湖路65#";
                tbMain.Rows[page * linep + 17][1] = "计划";


                tbMain.Rows[page * linep + 17][2] = "经纱总根数";
                tbMain.Rows[page * linep + 18][2] = "轴数";
                tbMain.Rows[page * linep + 19][2] = "每个稀轴根数";
                tbMain.Rows[page * linep + 20][2] = "经纱(kg)";
                tbMain.Rows[page * linep + 21][2] = "纬纱(kg)";
                tbMain.Rows[page * linep + 22][2] = "脚纱库存(kg)";
                tbMain.Rows[page * linep + 25][2] = "小计";
                //tbMain.Rows[page * linep + 29][1] = "备注";
                tbMain.Rows[page * linep + 26][1] = "染" + Environment.NewLine + "色" + Environment.NewLine + "安" + Environment.NewLine + "排" + Environment.NewLine + "记" + Environment.NewLine + "录";
                tbMain.Rows[page * linep + 26][2] = "前" + Environment.NewLine + "织" + Environment.NewLine + "附" + Environment.NewLine + "样";



                #endregion
                exAgent.SetCurrentSheet("JLTONAV95");
                DataRow dwVKP = dsSource.Tables["VKPOS"].Rows[0];
                string order = "";
                string 产品组 = "";
                #region=============Header==================
                tbMain.Rows[34]["F10"] = "日期:" + year + "年" + month + "月" + day + "日";
                string VKPART = dwVKP["VKPART"].ToString().Trim() + "-" + dwVKP["VKPFARBE"].ToString().Trim();
                tbMain.Rows[2]["F10"] = VKPART;
                exAgent.SetCurrentSheet("JLTAV95PLAN");
                exAgent.SetCellValue(2, 4, VKPART);
                exAgent.SetCurrentSheet("JLTONAV95");

                string 规格 = dwVKP["CONSTRUCTION"].ToString();
                产品组 = GetGB2312Value(dwVKP["ARTGRP"].ToString().Trim());
                tbMain.Rows[3]["F03"] = 规格.Replace("幅宽:", "  "); ;
                exAgent.SetCurrentSheet("JLTAV95PLAN");
                exAgent.SetCellValue(2, 6, 规格);
                exAgent.SetCellValue(2, 2, 产品组);
                exAgent.SetCurrentSheet("JLTONAV95");
                string 单位 = dwVKP["VKPMEEH"].ToString();

                string VKPMENGE1 = dwVKP["VKPMENGE1"].ToString();
                string VKPMEEHFKT = dwVKP["VKPMEEHFKT"].ToString();
                string 订单数量 = (Math.Ceiling(Convert.ToDecimal(VKPMENGE1)
                    * Convert.ToDecimal(VKPMEEHFKT)
                    * Convert.ToDecimal(0.001)
                    * Convert.ToDecimal(0.001)
                    * Convert.ToDecimal(0.01))).ToString();

                tbMain.Rows[30]["F03"] = 订单数量 + "M";
                exAgent.SetCurrentSheet("JLTAV95PLAN");
                exAgent.SetCellValue(15, 3, 订单数量 + "M");
                exAgent.SetCurrentSheet("JLTONAV95");
                string 交货范围 = dwVKP["OVERSHORT"].ToString();


                //string 交货日期 = dwVKP["ABAVKSTARTD"].ToString().Trim();
                string str1 = "", str2 = "", str3 = "";
                //Helper.GetSplitDate(ref str1, ref str2, ref str3, 交货日期);
                //tbMain.Rows[3]["F11"] = str3;
                //tbMain.Rows[2]["F03"] = str1;
                //exAgent.SetCurrentSheet("JLTAV95PLAN");
                //exAgent.SetCellValue(15, 7, str1);
                //exAgent.SetCurrentSheet("JLTONAV95");

                #endregion
                #region============计划===================
                bool IsJLengthPrinted = false;
                string 染色完成 = "", 浆纱完成 = "", 织造完成 = "", 坯布完成 = "", 整理完成 = "";
                string 备注 = "";
                string 投料范围 = "";

                string ABAWAKZ = "";
                string 整理缩率 = "";
                string 织造缩率 = "";
                string 零疵布 = "";
                string 成品数量 = "";
                string 坯布数量 = "";
                double 浆纱伸长 = 0;
                double 计划浆长 = 0;
                double 计划织轴 = 0;
                double 整经米数 = 0;
                double 浆纱浪费 = 0;
                string 翻单号 = "";
                string 织造机型 = "";
                string 整经方式 = "", 轴染类型 = "";
                string 存货成品数量 = "";
                string 制表 = "";
                string SQTYEND = "";
                foreach (DataRow dwABA in db.Tables["ICC_ABAX"].Rows)
                {
                    ABAWAKZ = dwABA["ABAWAKZ"].ToString();
                    switch (ABAWAKZ)
                    {
                        case "S":

                            break;
                        case "F":
                            SQTYEND = dwABA["QTYEND"].ToString();
                            tbMain.Rows[30]["F03"] = SQTYEND + "M";
                            exAgent.SetCurrentSheet("JLTAV95PLAN");
                            exAgent.SetCellValue(15, 3, SQTYEND + "M");
                            exAgent.SetCurrentSheet("JLTONAV95");
                            制表 = dwABA["ABAUSER"].ToString();
                            DataRow dwData = HR.SetProd.Tables["HRSTAMM"].NewRow();
                            dwData["HRMANDANT"] = app.Mandant;
                            dwData["HRBENID"] = 制表;
                            DataSet Set = HR.QueryHRSTAMM(dwData, 2);
                            foreach (DataRow row in Set.Tables[0].Rows)
                            {
                                制表 = GetGB2312Value(row["HRNNAME"].ToString()).Trim();
                                tbMain.Rows[page * linep + 34][4] = "制表：" + 制表;// +" " + year + "年" + month + "月" + day + "日";
                            }
                            翻单号 = dwABA["F02DES"].ToString().Trim();
                            存货成品数量 = dwABA["F02"].ToString().Trim();
                            tbMain.Rows[3]["F10"] = 翻单号;
                            tbMain.Rows[30]["F04"] = 存货成品数量 + "M";
                            //交货范围 = dwABA["R01DES"].ToString();

                            tbMain.Rows[30]["F09"] = GetGB2312Value(交货范围);
                            exAgent.SetCurrentSheet("JLTAV95PLAN");
                            exAgent.SetCellValue(15, 5, GetGB2312Value(交货范围));
                            exAgent.SetCurrentSheet("JLTONAV95");
                            投料范围 = dwABA["R01"].ToString().Trim();
                            tbMain.Rows[31]["F07"] = 投料范围 + "%";
                            整理完成 = dwABA["ABAVKENDD"].ToString();
                            Helper.GetSplitDate(ref str1, ref str2, ref 整理完成, 整理完成);
                            tbMain.Rows[27]["F11"] = 整理完成;
                            //exAgent.SetCurrentSheet("JLTAV95PLAN");
                            //exAgent.SetCellValue(13, 2, 整理完成);
                            //exAgent.SetCurrentSheet("JLTONAV95");
                            tbMain.Rows[2]["F03"] = str1;
                            exAgent.SetCurrentSheet("JLTAV95PLAN");
                            exAgent.SetCellValue(15, 7, str1);
                            exAgent.SetCurrentSheet("JLTONAV95");
                            成品数量 = dwABA["ABARESMG"].ToString();
                            tbMain.Rows[30]["F08"] = Convert.ToDouble(成品数量) / 1000 + "M";
                            break;
                        case "R":
                            备注 = dwABA["REMARK"].ToString();
                            tbMain.Rows[29]["F10"] = "备注:" + GetGB2312Value(备注.Replace("  ", " ").Replace(" ", Environment.NewLine));
                            整理缩率 = (Convert.ToDouble(dwABA["R01"].ToString()) / 100).ToString();
                            tbMain.Rows[31]["F05"] = 整理缩率 + "%";
                            零疵布 = dwABA["R02"].ToString();
                            //tbMain.Rows[5]["F07"] = 零疵布;

                            织造完成 = dwABA["ABAVKENDD"].ToString();
                            Helper.GetSplitDate(ref str1, ref str2, ref 织造完成, 织造完成);
                            //   tbMain.Rows[27]["F07"] = 织造完成;
                            坯布完成 = dwABA["ABAVKENDD"].ToString();
                            Helper.GetSplitDate(ref str1, ref str2, ref 坯布完成, 坯布完成);
                            //  tbMain.Rows[27]["F09"] = 坯布完成;
                            坯布数量 = dwABA["ABARESMG"].ToString();
                            tbMain.Rows[30]["F07"] = Convert.ToDouble(坯布数量) / 1000 + "M";
                            exAgent.SetCurrentSheet("JLTAV95PLAN");
                            exAgent.SetCellValue(17, 2, Convert.ToDouble(坯布数量) / 1000 + "M");
                            exAgent.SetCurrentSheet("JLTONAV95");
                            break;
                        case "W":
                        case "K":
                            织造机型 = GetGB2312Value(dwABA["R01DES"].ToString());
                            tbMain.Rows[2]["F06"] = 织造机型;
                            计划织轴 = Convert.ToDouble(dwABA["JNUM"].ToString());
                            tbMain.Rows[2]["F08"] = 计划织轴;
                            织造缩率 = dwABA["R01"].ToString();
                            tbMain.Rows[31]["F03"] = 织造缩率 + "%";
                            计划浆长 = Convert.ToDouble(dwABA["ABARESMG"].ToString());
                            tbMain.Rows[30]["F06"] = Convert.ToDouble(计划浆长) / 1000 + "M"; ;
                            浆纱完成 = dwABA["ABAVKENDD"].ToString();
                            Helper.GetSplitDate(ref str1, ref str2, ref 浆纱完成, 浆纱完成);
                            tbMain.Rows[27]["F05"] = 浆纱完成;
                            //exAgent.SetCurrentSheet("JLTAV95PLAN");
                            // exAgent.SetCellValue(8, 2, 浆纱完成);
                            //exAgent.SetCurrentSheet("JLTONAV95");
                            break;
                        case "G":
                            if (dwABA["ABPWAKZ"].ToString() == "W")
                            {
                                if (!IsJLengthPrinted)
                                {
                                    整经方式 = GetGB2312Value(dwABA["R01DES"].ToString());
                                    tbMain.Rows[29]["F05"] = 整经方式 + "米数";
                                    浆纱伸长 = Convert.ToDouble(dwABA["R01"].ToString());
                                    tbMain.Rows[31]["F09"] = 浆纱伸长 + "%";
                                    浆纱浪费 = Convert.ToDouble(dwABA["F01"].ToString());
                                    整经米数 = Convert.ToDouble(dwABA["F02"].ToString()) / 100;
                                    tbMain.Rows[30]["F05"] = Convert.ToDouble(整经米数) + "M";
                                    double 筒染整经米数 = Convert.ToDouble(dwABA["JWASTAGEDES"].ToString()) / 100;
                                    if (整经米数 != 筒染整经米数 && 筒染整经米数 > 0)
                                    {
                                        tbMain.Rows[30]["F05"] = 整经米数 + Environment.NewLine + 筒染整经米数 + "(筒)" + "M";
                                    }
                                    染色完成 = dwABA["ABAVKENDD"].ToString();
                                    IsJLengthPrinted = true;
                                }
                            }

                            Helper.GetSplitDate(ref str1, ref str2, ref 染色完成, 染色完成);
                            tbMain.Rows[27]["F03"] = 染色完成;
                            Helper.GetSplitDate(ref str1, ref str2, ref str3, 染色完成);
                            //exAgent.SetCurrentSheet("JLTAV95PLAN");
                            //exAgent.SetCellValue(6, 2, str1);
                            //exAgent.SetCurrentSheet("JLTONAV95");
                            break;
                        default:
                            break;
                    }
                }

                #endregion
                #region=====纱线列表===========
                string 色名 = "";
                string 色号 = "";
                string 纱支 = "";
                string 产地 = "";
                string 批号 = "";
                double 筒子只数 = 0;
                string 经纱定长米数 = "0";
                double 经纱公斤数 = 0;
                double 纬纱公斤数 = 0;
                double 轴染经纱根数 = 0;

                double 单轴色纱头份 = 0;
                double 轴染轴数 = 0;
                string 轴染大小轴 = "0";
                double 轴染公斤数 = 0;
                double 脚纱库存 = 0;
                double 合计 = 0;
                double 小计 = 0;
                double 保险系数 = 0;
                Dictionary<string, double> JW = new Dictionary<string, double>();
                int idx = 0;
                var qxd = from XD in db.Tables["ICC_ABAX"].AsEnumerable()
                          where XD["ABAWAKZ"].ToString() == "G"
                          && XD["ABAAUFTYP"].ToString() == "V"
                          orderby Convert.ToDouble(XD["ABAAUFPOS"].ToString()) ascending
                          group XD by new
                          {
                              ART = XD["ABAART"].ToString(),
                              FARBE = XD["ABAFARBE"].ToString(),
                              ABAUMART = XD["ABAUMART"].ToString().Trim(),
                              SELLERNAME = XD["SELLERNAME"].ToString().Trim(),
                          }
                              into g
                              select new
                              {
                                  KEY = g.Key,
                                  ABARESMG = g.Sum(XD => Convert.ToDouble(XD.Field<Decimal>("ABARESMG"))),
                              };

                int count = qxd.Count();
                for (idx = 0; idx < Math.Ceiling((double)(count / 7)); idx++)
                {
                    for (int j = 0; j < tbMain.Columns.Count; j++)
                    {
                        for (int i = 0; i < 30; i++)
                        {
                            tbMain.Rows[i + idx * linep][j] = tbMain.Rows[i][j];
                        }
                    }
                }
                idx = 0;
                page = 0;
                int linepage = 7;
                bool IsBeam = false;
                bool IsShowedBeam = false;
                string 纱线名称 = "";
                string SELLERNAME = "";
                foreach (var XD in qxd)
                {
                    string ART = XD.KEY.ART;
                    string COLOR = XD.KEY.FARBE;
                    SELLERNAME = XD.KEY.SELLERNAME;
                    小计 = XD.ABARESMG;
                    纬纱公斤数 = 0;
                    经纱公斤数 = 0;
                    经纱定长米数 = "0";
                    筒子只数 = 0;
                    产地 = "";
                    轴染大小轴 = "";
                    单轴色纱头份 = 0;
                    轴染轴数 = 0;
                    保险系数 = 0;
                    脚纱库存 = 0;
                    var query = from DataRow row in db.Tables["ICC_ABAX"].AsEnumerable()
                                where row["ABAWAKZ"].ToString() == "G"
                                && row["ABAART"].ToString() == ART
                                && row["ABAUMART"].ToString().Trim() == XD.KEY.ABAUMART.Trim()
                                && row["ABAAUFTYP"].ToString() == "V"
                                && row["ABAFARBE"].ToString() == COLOR
                                && row["SELLERNAME"].ToString().Trim() == SELLERNAME
                                //orderby row["ABPWAKZ"].ToString() descending
                                orderby Convert.ToDouble(row["ABAVKUPOS"].ToString()) ascending
                                select row;
                    foreach (DataRow row in query)
                    {
                        if (idx > (page + 1) * 6  & idx !=13)
                        {
                            NewPage(tbMain, page, page + 1, linep);
                            page++;
                        }
                        轴染类型 = row["ABAUMART"].ToString();
                        if (轴染类型.Trim().Length > 0)
                        {
                            switch (轴染类型.Trim())
                            {
                                case "D":
                                    轴染类型 = "大";
                                    break;
                                case "X":
                                    轴染类型 = "小";
                                    break;
                                case "M":
                                    轴染类型 = "迷你";
                                    break;
                            }
                            tbMain.Rows[page * linep + 18][2] = "轴数(" + 轴染类型.Trim() + ")";
                        }
                        色名 = GetGB2312Value(row["ABACOLORREF"].ToString());
                        纱支 = row["ABAART"].ToString();
                        纱线名称 = GetGB2312Value(纱支);
                        var qyarn = from DataRow dwGSDAT in db.Tables["GSDAT"].AsEnumerable()
                                    where dwGSDAT["GSART"].ToString().Trim() == 纱支.Trim()
                                    select dwGSDAT;
                        foreach (DataRow dwGSDAT in qyarn)
                        {
                            纱线名称 = GetGB2312Value(dwGSDAT["GSAGARNNR"].ToString()).Trim();
                        }
                        色号 = row["ABAFARBE"].ToString();
                        #region===产地/批号========
                        string _产地 = GetGB2312Value(row["SELLERNAME"].ToString()).Trim();
                        if (_产地.Length > 0)
                        {
                            if (!产地.Contains(_产地))
                            {
                                产地 += _产地;
                            }
                        }

                        if (产地.Trim().Length == 0)
                        {
                            string filter = "ABAAUFTYP='N' AND ABAVKAUFKRS='" + row["ABAAUFKRS"].ToString() + "' AND ABAVKAUFLFD='" + row["ABAAUFLFD"].ToString() + "' AND ABAVKAUFPOS='" + row["ABAAUFPOS"].ToString() + "'";
                            DataRow[] rows = db.Tables["ICC_ABAX"].Select(filter);
                            foreach (DataRow mat in rows)
                            {
                                产地 = mat["SELLERNAME"].ToString().Trim();
                                批号 = mat["SPINLOT"].ToString().Trim();
                            }
                        }
                        #endregion
                        脚纱库存 += Convert.ToDouble(row["ABAQTYALLOCATE"].ToString());
                        jstotal += Convert.ToDouble(row["ABAQTYALLOCATE"].ToString());
                        //小计 = 0;
                        double KG = Math.Ceiling(Convert.ToDouble(row["ABARESMG"].ToString()) / 1000);

                        轴染大小轴 = GetGB2312Value(row["ABAUMART"].ToString());//轴染类型

                        if (row["ABPWAKZ"].ToString() == "R")
                        {
                            纬纱公斤数 = KG;
                            wtotal += KG;
                        }
                        else
                        {
                            jtotal += KG;
                            if (轴染大小轴.Trim().Length > 0)
                            {
                                轴染公斤数 = KG;
                                轴染经纱根数 = Convert.ToDouble(row["TTENDS"].ToString());
                                单轴色纱头份 = Convert.ToDouble(row["UENDS"].ToString());
                                轴染轴数 = Convert.ToDouble(row["UNITNUM"].ToString());//轴个数 
                                IsBeam = true;
                                //tbMain.Rows[page * linep + 20][4 + idx - linepage * page - 1] = 轴染公斤数;
                                tbMain.Rows[page * linep + 17][4 + idx - linepage * page - 1] = 轴染经纱根数;//1000
                                tbMain.Rows[page * linep + 18][4 + idx - linepage * page - 1] = 轴染轴数;//6
                                //tbMain.Rows[page * linep + 19][4 + idx - linepage * page - 1] = 单轴色纱头份;//166
                                //4*167+2*166
                                if (轴染轴数 != 1)
                                {
                                    double rest = 轴染经纱根数 - 轴染轴数 * 单轴色纱头份;
                                    string exression = 轴染轴数 + "*" + 单轴色纱头份.ToString();
                                    if (rest > 0)
                                    {
                                        exression = rest + "*" + (单轴色纱头份 + 1).ToString() + "+" + (轴染轴数 - rest) + "*" + (单轴色纱头份).ToString();
                                    }
                                    tbMain.Rows[page * linep + 19][4 + idx - linepage * page - 1] = exression;
                                }
                                else
                                {
                                    tbMain.Rows[page * linep + 19][4 + idx - linepage * page - 1] = 1 + "*" + 轴染经纱根数;
                                }

                            }
                            else
                            {
                                保险系数 = Convert.ToDouble(row["F02DES"].ToString());
                                经纱公斤数 = KG;
                                经纱定长米数 = row["ABASSTKLG"].ToString();
                                筒子只数 = Convert.ToDouble(row["ABASANZSTK"].ToString());
                                string REMARK = row["REMARK"].ToString();
                                if (REMARK.Trim().Length > 2)
                                {
                                    经纱定长米数 = GetGB2312Value(REMARK).Trim();
                                }
                                tbMain.Rows[page * linep + 20][4 + idx - linepage * page - 1] = 经纱公斤数 + "(" + 保险系数 + ")";
                            }
                        }
                    }
                    if (!IsBeam)
                    {
                        if (!IsShowedBeam)
                        {
                            exAgent.HideRows(page * linep + 18, 1, page * linep + 20, 1);
                        }
                        tbMain.Rows[page * linep + 0][2] = "张家港市金陵纺织有限公司 生产计划单";
                    }
                    else
                    {
                        if (!IsShowedBeam)
                        {
                            exAgent.ShowRows(page * linep + 18, 1, page * linep + 20, 1);
                            IsShowedBeam = true;
                        }
                        tbMain.Rows[page * linep + 0][2] = "张家港市金陵纺织有限公司 盘头整经生产计划单";
                    }
                    tbMain.Rows[page * linep + 11][4 + idx - linepage * page - 1] = 色名.Trim();
                    //exAgent.SetCurrentSheet("JLTAV95PLAN");
                    //exAgent.SetCellValue(5, 2, 色名.Trim());
                    //exAgent.SetCurrentSheet("JLTONAV95");
                    //tbMain.Rows[page * linep + 11][10] = 合计;
                    tbMain.Rows[page * linep + 12][4 + idx - linepage * page - 1] = 色号.Trim();
                    tbMain.Rows[page * linep + 13][4 + idx - linepage * page - 1] = 纱线名称.Trim();// GetGB2312Value(纱支);
                    tbMain.Rows[page * linep + 14][4 + idx - linepage * page - 1] = 产地.Trim();// +"-" + 批号.Trim();
                    //tbMain.Rows[page * linep + 15][4 + idx - linepage * page - 1] = 筒子只数;
                    //tbMain.Rows[page * linep + 16][4 + idx - linepage * page - 1] = 经纱定长米数; 

                    tbMain.Rows[page * linep + 21][4 + idx - linepage * page - 1] = 纬纱公斤数;

                    tbMain.Rows[page * linep + 20][10] = jtotal;
                    tbMain.Rows[page * linep + 21][10] = wtotal;
                    //tbMain.Rows[page * linep + 22][4 + idx - linepage * page - 1] = 轴染大小轴;

                    tbMain.Rows[page * linep + 22][4 + idx - linepage * page - 1] = 脚纱库存;
                    tbMain.Rows[page * linep + 22][10] = jstotal;
                    tbMain.Rows[page * linep + 25][4 + idx - linepage * page - 1] = Math.Ceiling(小计 / 1000 - 脚纱库存).ToString();
                    tbMain.Rows[page * linep + 25][10] = jtotal + wtotal - jstotal;
                    idx++;
                }
                #endregion
                exAgent.DataTableToExcel(tbMain, 1, 1);
                exAgent.SetCurrentSheet("JLTONAV95");
                if (IsBeam)
                {
                    exAgent.Zoom(83);
                }
                else
                {
                    exAgent.Zoom(94);
                }
                exAgent.RenameSheet(VKPART);

            }
            catch (Exception ex)
            {
                msg = "有错误产生，请注意:";
                EventDispatcher.Instance.RaiseStatus(msg, StatusEventType.StopProgress);
                Tracer.Error(ex.StackTrace, ex);
            }
            finally
            {
                EventDispatcher.Instance.RaiseStatus(msg, StatusEventType.StopProgress);
            }
        }
        private void NewPage(DataTable tbMain, int page1, int page2, int linep)
        {

            for (int i = 0; i < linep; i++)
            {
                for (int j = 0; j < 11; j++)
                {
                    tbMain.Rows[page2 * linep + i][j] = tbMain.Rows[page1 * linep + i][j];
                }
            }
            for (int i = 11; i < 26; i++)
            {
                for (int j = 3; j < 11; j++)
                {
                    tbMain.Rows[page2 * linep + i][j] = " ";
                }
            }
            tbMain.Rows[page2 * linep + 20][10] = 0;
            tbMain.Rows[page2 * linep + 21][10] = 0;
            tbMain.Rows[page2 * linep + 22][10] = 0;
            tbMain.Rows[page2 * linep + 11][10] = "合计";
        }
    }
}